//
//  JWKBaseNavController.swift
//  Weibo
//
//  Created by 姜维克 on 16/5/20.
//  Copyright © 2016年 姜维克. All rights reserved.
//

import UIKit

class JWKBaseNavController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        
        self.interactivePopGestureRecognizer?.delegate = self
    }

    
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        //如果是顶级页面就不能滑动
        return childViewControllers.count > 1
        
    }
    
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        //设置标题
        if(childViewControllers.count > 0){
        viewController.navigationItem.title = "\(childViewControllers.count)"
    }
        if(childViewControllers.count > 1){
        let backItem = UIBarButtonItem.init(imageName: "navigationbar_back_withtext", title: "返回", target: self, action: #selector(back))
        
        viewController.navigationItem.leftBarButtonItem = backItem
        }
        
        super.pushViewController(viewController, animated: animated)
    }
    
    @objc private func back(){
        popViewControllerAnimated(true)
    }
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    

    
}
